package com.gnerv.battle.boot.module.base.controller;

import com.gnerv.battle.boot.module.base.model.dto.DictDetailsDTO;
import com.gnerv.battle.boot.common.base.model.RestResult;
import com.gnerv.battle.boot.module.base.business.DictBusiness;
import com.gnerv.battle.boot.module.base.model.dto.DictCreateDTO;
import com.gnerv.battle.boot.module.base.model.dto.DictDTO;
import com.gnerv.battle.boot.module.base.model.dto.DictUpdateDTO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "api/manage/dict")
public class DictController {

    private final DictBusiness dictBusiness;

    @PostMapping(value = "")
    public RestResult<Void> create(@RequestBody DictCreateDTO dictCreateDTO) {
        return dictBusiness.create(dictCreateDTO);
    }

    @DeleteMapping(value = "")
    public RestResult<Void> deleteByUkId(@RequestParam(value = "ukId") String ukId) {
        return dictBusiness.deleteByUkId(ukId);
    }

    @PutMapping(value = "")
    public RestResult<Void> updateByUkId(@RequestBody DictUpdateDTO dictUpdateDTO) {
        dictBusiness.updateByUkId(dictUpdateDTO);
        return RestResult.ok();
    }

    @GetMapping(value = "")
    public RestResult<DictDTO> selectByUkId(@RequestParam(value = "ukId") String ukId) {
        return dictBusiness.selectByUkId(ukId);
    }

    @GetMapping(value = "details/code")
    public RestResult<DictDetailsDTO> selectDetailsByCode(@RequestParam(value = "code") String code) {
        return dictBusiness.selectDetailsByCode(code);
    }

    @GetMapping(value = "list")
    public RestResult<List<DictDTO>> listByName(@RequestParam(required = false, value = "name") String name) {
        return dictBusiness.listByName(name);
    }

    @GetMapping(value = "details/list")
    public RestResult<List<DictDetailsDTO>> listDetailsByName(@RequestParam(required = false, name = "name") String name) {
        return dictBusiness.listDetailsByName(name);
    }

}
